;; The first three lines of this file were inserted by DrScheme. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname e1.7) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
(define (square x)
  (* x x ))

(define (good-enough? tolerance guess x)
  (< (abs (- (square guess) x)) tolerance))

(define (average x y)
  (/ (+ x y) 2))


;(define (improve guess x)
;  (average guess x))

(define (improve guess x)
  (average guess (/ x guess)))

(define (square-iter tolerance guess x)
  (if (good-enough? tolerance guess x)
      guess
      (square-iter tolerance (improve guess x) 
                 x)))

(define (test x y)
  (= x y))

(define sqrt2 1.41421356237309504880168872421)

(define (ogsquare tolerance initial-guess x)
  (square-iter tolerance initial-guess x))

; A aproximacao (representada por 'improve') tende lentamente ao valor
; esperado, o que torna o tempo total de execucao maior conforme aumenta o
; valor do numero.

; Para ajustar a tolerancia de 'good-enough?' foi adicionado um parametro.

; E para valores pequenos, qual o problema?